import {
    Component,
    Injector,
    ViewEncapsulation,
} from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    PipelineListDto,
    SimpleTechDocDto,
    PipelineNodeWorkerListDto,
    TechDocServiceProxy
} from '@shared/service-proxies/service-proxies';
import { PipelineNodesServiceProxy } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import { appModuleAnimation } from '@shared/animations/routerTransition';

@Component({
    selector: 'gy03',
    templateUrl: './gy03.component.html',
    styleUrls: ['./gy03.component.less'],
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()]
})
export class GY03ModalComponent extends AppComponentBase {
    saving = false;

    pipe: PipelineListDto = new PipelineListDto();

    nodeWorks = new Array<PipelineNodeWorkerListDto>();

    //actBase: ActBaseModalComponent;

    constructor(
        injector: Injector,
        private _taskServiceProxy: PipelineNodesServiceProxy ,
    ) {
        super(injector);
    }

    load(pipe: PipelineListDto): void {
        this.pipe = pipe;
        this._taskServiceProxy.getNodeWorkList(pipe.id).subscribe(result => {
           this.nodeWorks = result;
           //console.log(result);
        });
    }
    save(): void {
        this.saving = true;

        this._taskServiceProxy
            .updatePipelingWork(this.nodeWorks)
            .pipe(
                finalize(() => {
                    this.saving = false;
                })
            )
            .subscribe(result => {
                this.notify.success('保存成功');
            });
    }
}
